/**
 * @program: HelpLuojia
 * @description: 用于处理地理信息的工具
 * @author: PXM
 * @create: 2022-11-29 18:09
 **/
package com.whu.helpluojia.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

import java.util.Date;
import java.util.List;
import java.util.Random;

@Slf4j
public class EmailUtil {


    @Autowired
    JavaMailSender javaMailSender;

    /**
     * 发邮件
     */
    public void sendEmail(String destination,String code){
        log.info(destination+" "+code);
        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject("互助珞珈验证码");
        message.setFrom("1468735019@qq.com");
        message.setTo(destination);
        message.setSentDate(new Date());
        message.setText("您的验证码是："+code+"，有效期10分钟。");
        javaMailSender.send(message);
    }

    public static Integer generateCode(){
        Integer code;
        code = new Random().nextInt(9999);//生成随机数，最大为9999
        if(code < 1000){
            code = code + 1000;//保证随机数为4位数字
        }
        return code;
    }
}
